//
// Created by 吴锐 on 2022/3/3.
//

#include <vector>
#include "iostream"
#include "algorithm"

using namespace std;

void test01() {
    vector<int> v;
    for (int i = 0; i < 10; i++) {
        v.push_back(i);
    }

    //查找容器中是否有5
    vector<int>::iterator it = find(v.begin(), v.end(), 5);
    if (it == v.end()) {
        cout << "没有找到" << endl;
    } else {
        cout << "找到: " << *it << endl;
    }
}

class Person {
public:
    string m_Name;
    int m_Age;

    Person(string name, int age) {
        this->m_Name = name;
        this->m_Age = age;
    }

    bool operator==(const Person& p){
        if(this->m_Name == p.m_Name && this->m_Age == p.m_Age){
            return true;
        }else{
            return false;
        }
    }
};

void test02() {
    Person p1("aaa", 10);
    Person p2("bbb", 20);
    Person p3("ccc", 30);
    Person p4("ddd", 40);

    vector<Person> v;
    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);

    vector<Person>::iterator it = find(v.begin(), v.end(), p2);

    if (it == v.end()) {
        cout << "没有找到" << endl;
    } else {
        cout << "找到: " << "姓名: " << it->m_Name << " 年龄: " << it->m_Age << endl;
    }
}

int main() {
//    test01();
    test02();
    return 0;
}